package com.example.mallsystem1104.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * @Author zy
 * @Date 2024/12/10 15:47
 * @packageName:com.example.mallsystem1104.utils
 * @ClassName:Pathutils
 */
public class PathUtils {

    public static String getclassLoadRootPath(){
        String path="";
        try{
            String prePath = URLDecoder.decode(PathUtils.class.getClassLoader().getResource("").getPath(),"utf-8").replace("/target/classes","");
            String osName =System.getProperty("os.name");
            if(osName.toLowerCase().startsWith("mac")){
                // 苹果
                path = prePath.substring(0,prePath.length()-1);
            }else if(osName.toLowerCase().startsWith("windows")){//windows
                path = prePath.substring(1,prePath.length()-1);
            } else if(osName.toLowerCase().startsWith("linux")|| osName.toLowerCase().startsWith("unix")) {
                //unix or linux
                path = prePath.substring(0,prePath.length()-1);
            }else
            path = prePath.substring(1,prePath.length()-1);
        } catch(UnsupportedEncodingException e){
            e .printStackTrace();
        }
        return path;
    }

}
